package com.xianyun.site.support.executor.strategy.commond;

import com.alibaba.cola.dto.Response;
import com.xianyun.common.core.filter.FilterChain;
import com.xianyun.site.support.common.FilterChainFactory;
import com.xianyun.site.support.convertor.ReceiveConvertor;
import com.xianyun.site.support.domain.model.ReceiveMessage;
import com.xianyun.site.support.dto.ReceiveCmd;
import com.xianyun.site.support.executor.filter.support.BlockFilter;
import com.xianyun.site.support.executor.filter.support.OverdueFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.validation.Valid;

/**
 * @author mac_zyj
 */
@Slf4j
@Component
public class AnalysisStrategyExo {
    /**
     * 责任链配置
     */
    private final FilterChain<ReceiveMessage> filterChain;

    {
        filterChain = FilterChainFactory.buildFilterChain(
                BlockFilter.class,
                OverdueFilter.class
        );
    }

    public Response execute(@Valid ReceiveCmd receiveCmd){
        filterChain.doFilter(ReceiveConvertor.toEntity(receiveCmd));
        return Response.buildSuccess();
    }
}
